﻿// See https://aka.ms/new-console-template for more information

unsafe
{
    //注意：在任何时候都应该不要关注指针的存放地址而是关注指针存放的地址
    //栈数组 stackalloc 数据类型[分配单元数]:在栈分配内存块 
    var lenght = 10;
    int* pArr = stackalloc int[lenght];
    *(pArr + 5) = 996;
    pArr[6] = 12127;
    for (int i = 0; i < lenght; i++)
    {
        Console.WriteLine("Address:{0},Data:{1}",(ulong)(pArr+i),pArr[i]);//注意正括号表示法是直接取值的
    }

    Console.WriteLine("_____________________________________________数组越界测试_____________________________________________");

    for (int i = 0; i < lenght + 100; i++)//无越界检查
    {
        Console.WriteLine("Address:{0},Data:{1}", (ulong)(pArr + i), pArr[i]);
    }

    Console.WriteLine("_练习：使用QuickArray输出从0-14每个整数的平方结果_");
    Console.Write("Input:");
    int size = Convert.ToInt32(Console.ReadLine());
    long* pLongArray = stackalloc long[size];
    for (int i = 0; i < size; i++)
    {
        pLongArray[i] = i * i;
    }

    for (int i = 0; i < size; i++)
    {
        Console.WriteLine("Index:{0},Address:{1},Data:{2}", i,(ulong)(pLongArray + i), pLongArray[i]);
    }

}